package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsAddressMapper;
import com.qf.pojo.DtsAddress;
import org.apache.ibatis.javassist.runtime.Desc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author Wy
 * @version V1.0
 * @Project MavenDemo
 * @Package com.qf.service
 * @Description:
 * @Date 2022/7/4 21:17
 */
@Service
public class AddressServiceImpl  implements  AddressService{

       @Autowired
        private DtsAddressMapper mapper;

    @Override
    public IPage<DtsAddress> list(Integer page, Integer limit, String name, Integer id, String sort, String order) {
        IPage<DtsAddress> iPage = new Page<>(page,limit);

        QueryWrapper<DtsAddress> objectQueryWrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(name)){
            objectQueryWrapper.eq("username", name);
        }
        if(!StringUtils.isEmpty(id)){
            objectQueryWrapper.eq("id", id);
        }
        if(!StringUtils.isEmpty(sort)&&!StringUtils.isEmpty(order)){
           if(order.equalsIgnoreCase("asc")){
               objectQueryWrapper.orderByAsc();
           }else {
               objectQueryWrapper.orderByAsc();
           }
        }
        IPage<DtsAddress> iPage1 = mapper.selectPage(iPage, objectQueryWrapper);
        return iPage1;
    }
}
